

/**
 * @author 许喜朝
 *
 */
public class StrategyTest {
    public static void main(String[] args) {
        Zombie normalZombie1 = new NormalZombie1();
        normalZombie1.display();
        normalZombie1.move();
        normalZombie1.attrack();
        normalZombie1.setAttackable(new HitAttack());
        normalZombie1.attrack();
    }
}
//移动
interface Moveable{
    void move();
}
//攻击
interface Attackable{
    void attrack();
}
//抽象僵尸类
abstract class Zombie{
//    外观抽象方法
    abstract public void display();
    Moveable moveable;
    Attackable attackable;
    abstract void move();
    abstract void attrack();

    public Zombie(Moveable moveable, Attackable attackable) {
        this.moveable = moveable;
        this.attackable = attackable;
    }

    public Attackable getAttackable() {
        return attackable;
    }

    public void setAttackable(Attackable attackable) {
        this.attackable = attackable;
    }

    public Moveable getMoveable() {
        return moveable;
    }

    public void setMoveable(Moveable moveable) {
        this.moveable = moveable;
    }
}
//移动方式：一步一步移动
class StepByStepMove implements Moveable{

    @Override
    public void move() {
        System.out.println("一步一步移动");
    }
}
//攻击方式：咬
class BiteAttack implements Attackable{
    @Override
    public void attrack() {
        System.out.println("咬");
    }
}
//攻击方式：打
class HitAttack implements Attackable{
    @Override
    public void attrack() {
        System.out.println("打");
    }
}

//普通僵尸
class NormalZombie1 extends Zombie{

    public NormalZombie1() {
        super(new StepByStepMove(), new BiteAttack());
    }

    public NormalZombie1(Moveable moveable, Attackable attackable) {
        super(moveable, attackable);
    }

    @Override
    public void display() {
        System.out.println("普通僵尸");
    }

    @Override
    void move() {
        moveable.move();
    }

    @Override
    void attrack() {
        attackable.attrack();
    }
}
//旗手僵尸
class FlogZombie1 extends Zombie{
    public FlogZombie1(){
        super(new StepByStepMove(), new BiteAttack());
    }
    public FlogZombie1(Moveable moveable, Attackable attackable) {
        super(moveable, attackable);
    }

    @Override
    public void display() {
        System.out.println("旗手僵尸");
    }

    @Override
    void move() {
        moveable.move();
    }

    @Override
    void attrack() {
        attackable.attrack();
    }
}